#ifndef ASM_H
#define ASM_H

#include <types.h>

static inline uint8_t inb(uint16_t port) __attribute__((always_inline));
static inline void outb(uint16_t port, uint8_t data) __attribute__((always_inline));
static inline uint32_t read_esp(void) __attribute__((always_inline));
static inline uint32_t read_ebp(void) __attribute__((always_inline));

static inline uint8_t
inb(uint16_t port){
	uint8_t data;
	asm volatile (
		"inb %1,%0"
		: "=a" (data)
		: "d" (port)
	);
	return data;
}

static inline void
outb(uint16_t port, uint8_t data){
	asm volatile (
		"outb %0,%1"
		: 
		: "a" (data), "d" (port)
	);
}

static inline uint32_t 
read_esp(void){
	uint32_t esp;
	asm volatile (
		"movl %%esp,%0"
		: "=r" (esp)
	);
	return esp;
}

static inline uint32_t 
read_ebp(void){
	uint32_t ebp;
	asm volatile (
		"movl %%ebp,%0"
		: "=r" (ebp)
	);
	return ebp;
}


#endif  // ASM_H